package com.situ.student.service.impl;

import java.util.List;

import com.situ.student.dao.IStudentDao;
import com.situ.student.dao.impl.StudentDaoImpl;
import com.situ.student.entity.Student;
import com.situ.student.exception.IdNotFoundException;
import com.situ.student.exception.NameRepeatException;
import com.situ.student.service.IStudentService;

public class StudentServiceImpl implements IStudentService{
	private IStudentDao studentDao = new StudentDaoImpl();
	@Override
		public boolean register(Student student) throws NameRepeatException {
			if (studentDao.checkName(student.getName())) {
				throw new NameRepeatException("该用户名已经存在");
			} else {
				int result = studentDao.insert(student);
				if (result > 0) {
					return true;
				} else {
					return false;
				}
			}
		}
	@Override
	public List<Student> findAll() {
		return studentDao.findAll();
	}
	@Override
	public boolean delete(Student student) throws IdNotFoundException {
		if (studentDao.checkNames(student.getId())) {
			throw new IdNotFoundException("没有此id");
		} else {
			int count = studentDao.shanChu(student);
			if (count > 0) {
				return true;
			} else {
				return false;
			}
		}
	}
	@Override
	public boolean update(Student student) throws IdNotFoundException {
		if (studentDao.checkNames(student.getId())) {
			throw new IdNotFoundException("没有此id");
		} else {
			int count = studentDao.update(student);
			if (count > 0) {
				return true;
			} else {
				return false;
			}
		}
	}

}
